package com.cloudlead.common.lang.serialize;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;

import javax.xml.bind.annotation.adapters.XmlAdapter;

import com.cloudlead.common.lang.utils.DateTimeConvertUtils;

/**
 * 自定义日期序列化格式
 * 
 * @author dean.lu
 * 
 */
public class TimestampAdapter extends XmlAdapter<String, Timestamp> {
	private SimpleDateFormat dateTimeFormat = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss.S");

	@Override
	public String marshal(Timestamp v) throws Exception {
		return dateTimeFormat.format(v);
	}

	@Override
	public Timestamp unmarshal(String v) throws Exception {
		return DateTimeConvertUtils.convertToTimestamp(v);
	}
}
